package com.ruoyi.project.socket.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadUtil {

    //线程工厂
    private static ThreadFactory factory = new ThreadFactory() {
        AtomicInteger atomic = new AtomicInteger(1);
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r,"JavaThread--"+atomic.getAndIncrement());
            return thread;
        }
    };


    private static ThreadPoolExecutor exec = new ThreadPoolExecutor
            (100,
                    1000,
                    5,
                    TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>(),
                    factory,
                    new ThreadPoolExecutor.AbortPolicy());

    public static void execute(Runnable runnable){
        exec.execute(runnable);
    }
}
